cmake_minimum_required(VERSION 3.13.0)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# dont print useless messages
set(CMAKE_RULE_MESSAGES off)
# output verbose log
set(CMAKE_VERBOSE_MAKEFILE on)

# enable cmake_print_variables()
include(CMakePrintHelpers)

set(CMAKE_ASM_NASM_COMPILER nasm)
set(CMAKE_ASM_NASM_COMPILE_OBJECT "nasm <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")

# demonstrate the linker program
set(CMAKE_ASM_NASM_LINK_EXECUTABLE "nasm <LINK_FLAGS> <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

# preprocess only (writes output to stdout by default)
set(CMAKE_ASM_NASM_FLAGS "-e")

set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS asm nasm s S)

set(CMAKE_C_COMPILER "/usr/bin/gcc-4.4")
set(CMAKE_C_LINK_EXECUTABLE "ld <FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_C_STANDARD_REQUIRED true)
set(CMAKE_C_STANDARD 99)

# enable symbol table
# set(CMAKE_C_FLAGS "-g")

# low compile level
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")

set(CMAKE_ASM_NASM_OUTPUT_EXTENSION bin)

set(CMAKE_ASM_NASM_OBJECT_FORMAT elf)

# Project Info
project(OSReduction 
  LANGUAGES C CXX ASM_NASM 
  VERSION 0.1.3)
enable_language(ASM_NASM)

# Output directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_subdirectory(boot)
add_subdirectory(kernel)
add_subdirectory(lib)

message("------------- ASM Info -----------------")
cmake_print_variables(
  CMAKE_ASM_NASM_COMPILER
  CMAKE_ASM_NASM_FLAGS

  CMAKE_ASM_NASM_LINK_EXECUTABLE
  CMAKE_ASM_NASM_COMPILE_OBJECT
  )
